package com.bcntouch.touch2act.Opine;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.bcntouch.touch2act.R;
import com.bcntouch.touch2act.Constants.Constants;

public class OpineActivity extends Activity {

	public final static String EXTRA_OPINION_ID = Constants.AUTHORITY + ".OPINION_ID";
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_opine);
//        getActionBar().setDisplayHomeAsUpEnabled(true);
        
        final Opinion[] opinions = Opinions.getOpinionsArray(this);
        ArrayAdapter<Opinion> adapter = new ArrayAdapter<Opinion>(this, android.R.layout.simple_list_item_1, opinions);
        ListView listView = (ListView) findViewById(R.id.available_opinions);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				onOpinionSelected(opinions[position]);
			}
		});
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_opine, menu);
        return true;
    }

    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                NavUtils.navigateUpFromSameTask(this);
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
    
    public void onOpinionSelected(Opinion opinion) {
    	Intent intent = new Intent(this, OpinionTagDetectedActivity.class);
    	intent.putExtra(EXTRA_OPINION_ID, opinion.getId());
    	startActivity(intent);
    }

}
